﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class CreateImage : MonoBehaviour {
   public void CreateImageElement()
    {
        GameObject obj = GameObject.Find("Canvas");
        GameObject img = new GameObject("RoleImage");
        img.transform.SetParent(obj.transform);
        img.AddComponent<Image>();
        img.GetComponent<RectTransform>().sizeDelta = new Vector2(400f, 800f);
        //改变RectTransform的top
        img.GetComponent<RectTransform>().offsetMax = new Vector2(img.GetComponent<RectTransform>().offsetMax.x+300, 200f);
        //改变RectTransform的bottom
        img.GetComponent<RectTransform>().offsetMin = new Vector2(img.GetComponent<RectTransform>().offsetMin.x+300, -180f);
        string x = "";
    }
}